package com.lims.landInfo.action;

import cn.org.rapid_framework.web.scope.Flash;

import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ModelDriven;

import javacommon.base.*;

import cn.org.rapid_framework.page.*;

import com.lims.landInfo.model.*;
import com.lims.landInfo.service.*;
import com.lims.landInfo.vo.query.*;

/**
 * @author zzh
 * @version 1.0
 * @since 1.0
 */
@SuppressWarnings({ "unchecked", "serial" })
public class CorporationAction extends BaseStruts2Action implements Preparable,ModelDriven{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	
	//forward paths
	protected static final String QUERY_JSP = "/pages/landInfo/Corporation/query.jsp";
	protected static final String LIST_JSP= "/pages/landInfo/Corporation/list.jsp";
	protected static final String CREATE_JSP = "/pages/landInfo/Corporation/create.jsp";
	protected static final String EDIT_JSP = "/pages/landInfo/Corporation/edit.jsp";
	protected static final String SHOW_JSP = "/pages/landInfo/Corporation/show.jsp";
	//redirect paths,startWith: !
	protected static final String LIST_ACTION = "!/pages/landInfo/Corporation/list.do";
	
	private CorporationManager corporationManager;
	
	private Corporation corporation;
	java.lang.String id = null;
	private String items;

	public void prepare() throws Exception {
		if (isNullOrEmptyString(id)) {
			corporation = new Corporation();
		} else {
			corporation = (Corporation)corporationManager.getById(id);
		}
	}
	
	/** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,注意大小写 */
	public void setCorporationManager(CorporationManager manager) {
		this.corporationManager = manager;
	}	
	
	public Object getModel() {
		return corporation;
	}
	
	public void setObjid(java.lang.String val) {
		this.id = val;
	}

	public void setItems(String items) {
		this.items = items;
	}
	
	/** 执行搜索 */
	public String list() {
		CorporationQuery query = newQuery(CorporationQuery.class,DEFAULT_SORT_COLUMNS);
		Page page = corporationManager.findPage(query);
		savePage(page,query);
		return LIST_JSP;
	}
	
	
	
	/** 查看对象*/
	public String show() {
		return SHOW_JSP;
	}
	
	/** 进入新增页面*/
	public String create() {
		return CREATE_JSP;
	}
	
	/** 保存新增对象 */
	public String save() {
		corporationManager.save(corporation);
		Flash.current().success(CREATED_SUCCESS); //存放在Flash中的数据,在下一次http请求中仍然可以读取数据,error()用于显示错误消息
		return LIST_ACTION;
	}
	
	/**进入更新页面*/
	public String edit() {
		return EDIT_JSP;
	}
	
	/**保存更新对象*/
	public String update() {
		corporationManager.update(this.corporation);
		Flash.current().success(UPDATE_SUCCESS);
		return LIST_ACTION;
	}
	
	/**删除对象*/
	public String delete() {
		String[] objids = items.split(",");
		for (int i = 0; i < objids.length; i++) {		
			corporationManager.removeById(objids[i]);
		}
		//Flash.current().success(DELETE_SUCCESS);
		return LIST_ACTION;
	}

}
